package kr.co.graviti.service.cd;

import java.util.HashMap;
import java.util.List;

import kr.co.graviti.common.util.CommonUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@SuppressWarnings("unchecked")
public class CdServiceImp implements CdService{
	
	@Autowired 
	private SqlMapClientTemplate sqlMapClientTemplate;
	
	@Override
	public List<HashMap<String, Object>> selectCdList(HashMap<String, Object> param){
		return (List<HashMap<String,Object>>)this.sqlMapClientTemplate.queryForList("Common.cdinfoList",param);
	}	
	
	/**
	 * 공통Use Insert 
	 */
	@Override
	public void commInsert(){
		this.sqlMapClientTemplate.insert("Common.commInsert");
	}
	
	/** 공통코드 등록
	 * @param param
	 */
	@Override
	public void cdInsert(HashMap<String, Object> param){
		this.sqlMapClientTemplate.insert("Common.cdInsert",param);
	}
	
	/** 공통코드 수정
	 * @param param
	 */
	@Override
	public void cdUpdate(HashMap<String, Object> param){
		this.sqlMapClientTemplate.insert("Common.cdUpdate",param);
	}
	
	/** 공통코드 삭제 
	 * @param param
	 */
	@Override
	public void cdDelete(HashMap<String, Object> param){
		this.sqlMapClientTemplate.insert("Common.cdDelete",param);
	}
	
	/** 최신 insert view
	 * @return
	 */
	@Override
	public int selectCommIdx(){
		return (Integer)this.sqlMapClientTemplate.queryForObject("Common.commVal");
	}
	
	/** 공통 파일등록
	 * @param param
	 */
	@Override
	public void fileInsert(HashMap<String, Object> param){
		this.sqlMapClientTemplate.insert("Common.fileInsert",param);
	}
	
	/** 공통 파일 수정 
	 * @param param
	 */
	@Override
	public void fileUpdate(HashMap<String, Object> param){
		this.sqlMapClientTemplate.update("Common.fileUpdate",param);
	}
	
	/** 공통 파일 삭제 cdInsert
	 * @param param
	 */
	@Override
	public void fileDelete(HashMap<String, Object> param){
		this.sqlMapClientTemplate.delete("Common.fileDelete",param);
	}
	
	
	/* (non-Javadoc)
	 * @see kr.co.graviti.service.cd.CdService#cdinfoPagingList(java.util.HashMap)
	 */
	@Override
	public List<HashMap<String, Object>> cdinfoPagingList(HashMap<String, Object> param){
		return (List<HashMap<String, Object>>)this.sqlMapClientTemplate.queryForList("Common.cdinfoPagingList",param);
	}
	
	@Override
	public List<HashMap<String, Object>> cdinfoNoneList(HashMap<String, Object> param){
		return (List<HashMap<String, Object>>)this.sqlMapClientTemplate.queryForList("Common.cdinfoNoneList",param);
	}
	
	/* (non-Javadoc)
	 * @see kr.co.graviti.service.cd.CdService#cdinfoTotalCnt(java.util.HashMap)
	 */
	@Override
	public int cdinfoTotalCnt(HashMap<String, Object> param){
		return (Integer)this.sqlMapClientTemplate.queryForObject("Common.cdinfoTotalCnt", param);
	}
	
	@Override
	public HashMap<String, Object> cdViewer(HashMap<String, Object> parma){
		return (HashMap<String, Object>)this.sqlMapClientTemplate.queryForObject("Common.cdViewer", parma);
	}
	/** 첨부파일 리스트 
	 * @param param
	 * @return
	 */
	public List<HashMap<String, Object>> fileselect(HashMap<String, Object> param){
		return (List<HashMap<String, Object>>)this.sqlMapClientTemplate.queryForList("Common.fileselect",param);
	}
	
	/** 공통코드 HashMap
	 * @param cd_lst
	 * @param cd
	 * @param qorder
	 * @return
	 */
	public HashMap<String, Object> commcd(String cd_lst,String cd,String qorder){
		HashMap<String, Object> cdparam = new HashMap<String, Object>();
		
		if(!CommonUtil.strNullChk(cd_lst).equals("")) cdparam.put("cd_lst", cd_lst);
		if(!CommonUtil.strNullChk(cd).equals("")) cdparam.put("cd", cd);
		if(!CommonUtil.strNullChk(qorder).equals("")) cdparam.put("qorder", qorder);
		
		return cdparam;
	}

	/* (non-Javadoc)
	 * 첨부파일 그룹아이디로 삭제
	 * @see kr.co.graviti.service.cd.CdService#fileDeleteByattchfileidx(java.util.HashMap)
	 */
	@Override
	public void fileDeleteByattchfileidx(HashMap<String, Object> param) {
		// TODO Auto-generated method stub
		this.sqlMapClientTemplate.delete("Common.fileDeleteByattchfileidx",param);
	}
	
	@Override
	public int selectcountreform(HashMap<String, Object> param){
		return (Integer)this.sqlMapClientTemplate.queryForObject("Common.selectcountreform", param);
	}
	
	@Override
	public int filemaxidx(){
		return (Integer)this.sqlMapClientTemplate.queryForObject("Common.filemaxidx");
	}
	
}
